﻿using EntityModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace EGS.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class PayfeesController : ControllerBase
    {
        private readonly EGSDbContext db;
        public PayfeesController(EGSDbContext context)
        {
            db = context;
        }
        [HttpGet("GetAll")]
        public List<EGS_Payfees> GetAll()
        {
            return db.Payfees.ToList();
        }
        [HttpGet("{id}")]
        public EGS_Payfees? GetEGS_PayfeesById(Guid id)
        {
            EGS_Payfees? pay = new EGS_Payfees();
            pay = db.Payfees.Where(p => p.ID == id).FirstOrDefault();
            return pay;
        }
        [HttpPost]
        public Result AddPayfees([FromBody] EGS_Payfees pay)
        {
            Result result = new Result();
            db.Payfees.Add(pay);
            result.Data = db.SaveChanges();
            return result;
        }
        [HttpDelete]
        public Result DelPayfees(Guid Id)
        {
            Result? result = new Result();
            EGS_Payfees? pay = new EGS_Payfees();
            pay = db.Payfees.Where(p => p.ID == Id).FirstOrDefault();
            //int result = 0;
            if (pay != null)
            {
                db.Payfees.Update(pay);
                result.Data = db.SaveChanges();
                //result.Code = 200;
                //result.Time = DateTime.Now;
                //result.Name = "张三";
            }
            return result;
        }
        [HttpPut]
        public Result UpPayfees([FromBody] EGS_Payfees pay)
        {
            Result result = new Result();
            db.Payfees.Update(pay);
            result.Data = db.SaveChanges();

            return result;
        }
   
    }
}
